import {
  Get,
  Controller,
  Post,
  Response,
  Param,
  HttpStatus,
  Request,
  UseGuards,
  Body,
  UsePipes,
  Query,
  Put,
} from '@nestjs/common';
import { GoodsService } from './goods.service';
import { CreateDto, PutDto } from './goods.dto';
import { Roles } from '../../auth/roles.decorator';
import { RolesGuard } from '../../auth/roles.guard';

@Controller('goods')
export class GoodsController {
  constructor(private readonly goodsService: GoodsService) {}

  @Roles('admin')
  @UseGuards(RolesGuard)
  @Post('create')
  create(@Body() param: CreateDto) {
    return this.goodsService.create(param);
  }

  @Roles('admin')
  @UseGuards(RolesGuard)
  @Post('delete')
  delete(@Body('id') id: number) {
    return this.goodsService.delete(id);
  }

  @Roles('admin')
  @UseGuards(RolesGuard)
  @Get('getInfoById')
  getInfoById(@Query('id') id: number) {
    return this.goodsService.getInfoById(id);
  }

  @Roles('admin')
  @UseGuards(RolesGuard)
  @Post('put')
  put(@Body() param: PutDto) {
    return this.goodsService.put(param);
  }

  @Roles('admin')
  @UseGuards(RolesGuard)
  @Get('list')
  getStoreList(
    @Query('page') page: string,
    @Query('pageSize') pageSize: string,
    @Query('name') name: string,
    @Query('type') type: number,
  ): Promise<object> {
    return this.goodsService.getList(
      Number(page),
      Number(pageSize),
      name,
      Number(type),
    );
  }
}
